package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.childMchListBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.childMchListCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
/**
*下级商户列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_childMchList{
	private static childMchListBean bean;
	private static childMchListCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("下级商户列表");
	}

	@Before
	public void caseUp() {
		bean=new childMchListBean();
		call=new childMchListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_childMchList_001() {
		Logger.start(true,"下级商户列表-返回成功");
		try {
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            //供货商
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
            Thread.sleep(5000);
            registerByCodeBean registerByCodeBean1=GodmchManageCallService.initRegisterByCode(mchId, createSupplierCodeCall.getCode());
            registerByCodeCall registerByCodeCall1=GodmchManageCallService.registerByCodeCall(registerByCodeBean1);
            //渠道商
            String inviteCode= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean2=GodmchManageCallService.initRegisterByCode(mchId, inviteCode);
            registerByCodeCall registerByCodeCall2=GodmchManageCallService.registerByCodeCall(registerByCodeBean2);  
            
            bean.setShopId(registerByCodeCall1.getRegMchId());
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_childMchList_003() {
		Logger.start(true,"下级商户列表-2渠道商-返回成功");
		try {
			//1:独立商户1创建邀请码  2：独立商户1注册渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);

			//mchId2 渠道
            String code= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, code);
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            GodmchManageCallService.bindRelation(registerByCodeCall.getRegMchId(),createCodeCall.getCode());
            
            bean.setShopId(mchId);
            bean.setPageIndex(1);
            bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(1, call.getTotal(), "验证总数Total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	} 
}